﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPage2 : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["cashierpos"] != null)
        {
            Label1.Text = "You are logged in as " + Session["cashierpos"].ToString();
            login.Visible = false;
        }
    
    }
    public void DIS_ID_TextChanged(object sender, EventArgs e)
    {

        if (CI.Checked)
        {

            if (idisok(DIS_ID.Text))
            {
                Session["name"] = DIS_ID.Text;
                Session["user"] = DIS_ID.Text;
                Label2.Text = DIS_ID.Text;
            }
            else { Label2.Text = "Invalid ID Number"; }
        }
        else
        {
            string disid = DIS_ID.Text;
            string check_name = disid;

            int id_length = disid.Length;

            if (id_length > 2)
            {
                check_name = disid.Substring(0, 2);
            }
            else
            {
                check_name = disid;
            }


            if (check_name.Equals("EM"))
            {
                Bestlife.ERP.Entities.E_Employee empEn = new Bestlife.ERP.Entities.E_Employee();

                Bestlife.ERP.DataAccess.D_Employee emp = new Bestlife.ERP.DataAccess.D_Employee();
                empEn = emp.Employee_return(disid);
                if (empEn.Employee_iD == null)
                {
                    Label2.Text = "Invalid Employee Number";
                }
                else
                {
                    Label2.Text = empEn.Employee_name.ToString();
                    Session["user"] = disid;
                    Session["name"] = Label2.Text;
                }
            }
            else
            {
                Bestlife.ERP.DataAccess.D_POS pos = new Bestlife.ERP.DataAccess.D_POS();
                Label2.Text = pos.pos(disid);
                Session["user"] = disid;
                Session["name"] = Label2.Text;
            }

        }




        //if (CI.Checked)
        //{
            
        //    Session["name"] = DIS_ID.Text;
        //    Session["user"] = DIS_ID.Text;
        //    Label2.Text = DIS_ID.Text;
        //}
        //else 
        //{
        //    string disid = DIS_ID.Text;
        //    string check_name = disid;

        //    int id_length = disid.Length;

        //    if (id_length > 2)
        //    {
        //        check_name = disid.Substring(0, 2);
        //    }
        //    else
        //    {
        //        check_name = disid;
        //    }


        //    if (check_name.Equals("EM"))
        //    {
        //        Bestlife.ERP.Entities.E_Employee empEn = new Bestlife.ERP.Entities.E_Employee();

        //        Bestlife.ERP.DataAccess.D_Employee emp = new Bestlife.ERP.DataAccess.D_Employee();
        //        empEn = emp.Employee_return(disid);
        //        if (empEn.Employee_iD == null)
        //        {
        //            Label2.Text = "Invalid Employee Number";
        //        }
        //        else
        //        {
        //            Label2.Text = empEn.Employee_name.ToString();
        //            Session["user"] = disid;
        //            Session["name"] = Label2.Text;
        //        }
        //    }
        //    else
        //    {
        //        Bestlife.ERP.DataAccess.D_POS pos = new Bestlife.ERP.DataAccess.D_POS();
        //        Label2.Text = pos.pos(disid);
        //        Session["user"] = disid;
        //        Session["name"] = Label2.Text;
        //    }

        //}
    }
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {

    }

    public Boolean idisok(string ids)
    {
        Boolean tf = false;

        int idlength = ids.Length;
        string lastch = ids.Substring(idlength - 1);

        if ((lastch.Equals("V") || lastch.Equals("v") || lastch.Equals("X") || lastch.Equals("x")) && (ids.Length == 10))
        {
            tf = true;
        }

        return tf;
    }

}
